package com.rui.cn.provider.service.system.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rui.cn.entity.system.SysRole;
import com.rui.cn.provider.repository.system.SysRoleDao;
import com.rui.cn.provider.service.system.SysRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 角色 服务实现类
 * </p>
 *
 * @author zhang123
 * @since 2018-01-14
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysRoleServiceImpl extends ServiceImpl<SysRoleDao,SysRole> implements SysRoleService {

    @Autowired
    private SysRoleDao sysRoleDao;
    @Override
    public List<SysRole> getRoleList(Integer id) {
        return  sysRoleDao.getRoleList(id);
    }
    /**
     *@ 描述：角色列表
     *@ 方法名：roleList
     *@ 参数：[pagination, search, sortBy, order]
     *@ 返回值类型：java.util.List<com.rui.cn.entity.system.SysRole>
     *@ 创建人：[zhang]
     *@ 创建时间：2018/4/28 0028-下午 15:26
     **/
    @Override
    public Page<SysRole> roleList(Page pagination, String search, String sortBy, String order) {
        EntityWrapper<SysRole> ew = new EntityWrapper<SysRole>();
        ew.setEntity(new SysRole());
        ew.like("rolename",search).or().like("roledesc",search);
        if(StringUtils.isNotBlank(sortBy)){
            ew.and().orderBy(sortBy,order.equals("desc")?false:true);
        }
        return pagination.setRecords(sysRoleDao.selectPage(pagination,ew));
    }

    @Override
    public List<SysRole> selectUserRole(Integer id) {
        return sysRoleDao.selectUserRole(id);
    }
}
